/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import persistence.rb_raw_materials_persist;
import vo.rb_manufacturing;
import vo.rb_raw_materials;

/**
 *
 * @author Shuhail
 */
public class test_rb_raw_materials {
    
     
    Session sess=null;
    Transaction tx=null;
    static {
       
    }

    public test_rb_raw_materials() {
         SessionFactory sf=new Configuration().configure().buildSessionFactory();
       
        sess=sf.openSession();
        tx=sess.beginTransaction();
    }
    
    public void fetch() {
        
        tx.begin();
        Query query=sess.getNamedQuery("getAllRawMaterials");
        List res=query.list();
        Iterator it=res.iterator();
        for(int i=0;i<res.size();i++) {
            rb_raw_materials r=(rb_raw_materials)res.get(i);
            System.out.println(r.getRaw_mat_id()+"----"+r.getRaw_mat_name()+"-----"+r.getRaw_mat_type());
        }
    }
    public static void main(String[] args) {
        /*
        List<rb_raw_materials> rlist=new rb_raw_materials_persist().fetch();
         String[] s;
            s=new String[rlist.size()];
            
        for(int i=0;i<rlist.size();i++) {
            rb_raw_materials rm=(rb_raw_materials)rlist.get(i);
            System.out.println(rm.getRaw_mat_name());
           s[i]=rm.getRaw_mat_id();
        }
        System.out.println(s[1]);
        * */
        
        rb_raw_materials_persist r=new rb_raw_materials_persist();
        rb_raw_materials rr=new rb_raw_materials();
        rr.setRaw_mat_name("shu");
        rr.setRaw_mat_type("Chemical");
        r.insert(rr);
        
    }
    
    
}
